<template>
    <!--最大div-->
    <div style="margin-top: -10px">
        <!--新建栏-->
        <div style="border:1px solid #BFBFBF;padding: 10px;background-color: white;margin-top: 10px;height: 40px">
            <el-row :gutter="24">
                <el-col :span="2">
                    <span style="font-size: 18px;line-height:40px;margin-left: 5px">费用类型</span>
                </el-col>
                <el-col :span="7">
                    <el-select v-model="fenlei" @change="changebusni" style="width: 150px;margin-left: 20px" placeholder="全部数据">
                        <el-option-group
                                v-for="group in options3"
                                :key="group.label"
                                :label="group.label">
                            <el-option
                                    v-for="item in group.options"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-option-group>
                    </el-select>
                    <el-button style="background-color: #f05050;color: white;margin-left: 10px;" @click="cancelseek" icon="el-icon-back" v-show="seek" size="mini" round>解除搜索</el-button>
                </el-col>
                <el-col :span="9">
                    <el-input placeholder="请输入经办人的信息" v-model="search" style="width: 250px;" @keyup.enter.native="ajaxLoginApi()">
                        <i slot="suffix" class="el-input__icon el-icon-search"></i>
                    </el-input>
                </el-col>
                <el-col :span="6">
                    <router-link :to="{path:'/xsfytk'}">
                        <el-button size="small"  type="primary" @click="jilutankuan=true">新建申请</el-button>
                    </router-link>
                </el-col>
            </el-row>
        </div>



        <!--表格数据框-->
        <div style="margin-top: 10px;border: 1px solid #BFBFBF;background-color: white">
            <div style="width: 100%;height: 40px;background-color: white;border-bottom: 1px solid #EBEEF5">
                <div class="operate" v-show="cjy">
                    <div class="selected—title" style="border-right: 0px ;width: 100%;">
                        场景：<span>{{fenlei}}</span>
                    </div>
                </div>
                <div class="operate" v-show="cje">
                    <div class="selected—title" >
                        已选中<span class="selected—count">{{count}}</span>项
                    </div>

                    <div  class="selected—title1" v-show="isOne">
                        <span><i class="el-icon-edit"></i>修改</span>
                    </div>
                    <div  class="selected—title1">
                        <span><i class="el-icon-delete"></i>删除</span>
                    </div>
                </div>
            </div>
            <el-table
                    :data="xsfylist"
                    style="width: 100%"
                    max-height="450"
                    :default-sort = "{prop: 'date', order: 'descending'}"
                    @selection-change="handleSelectionChange">
                <el-table-column
                        type="selection"
                        width="50"
                        align="center">
                </el-table-column>
                <el-table-column
                        fixed
                        prop="xsfyId"
                        label="ID"
                        sortable
                        align="center"
                        width="60">
                </el-table-column>
                <el-table-column
                        fixed
                        label="经手人"
                        prop="empId.empName"
                        align="center"
                        width="150">
                </el-table-column>
                <el-table-column
                        prop="xsfyKh"
                        label="客户"
                        align="center"
                >
                </el-table-column>
                <el-table-column
                        label="日期"
                        align="center"
                        sortable
                >
                    <template slot-scope="d">
                        {{d.row.xsfyDate | formatDate}}
                    </template>
                </el-table-column>
                <el-table-column
                        prop="xsfyJe"
                        label="金额"
                        align="center"
                        sortable
                >
                </el-table-column>
                <el-table-column
                        prop="xsfyLb"
                        label="费用类别"
                        align="center"
                >
                </el-table-column>
                <el-table-column
                        prop="xsfySpzt"
                        label="审批状态"
                        align="center"
                >
                </el-table-column>
                <el-table-column
                        prop="xsfyBx"
                        label="报销"
                        align="center"
                >
                </el-table-column>
<!--                <el-table-column-->
<!--                        prop="xsfySpr"-->
<!--                        label="审批人"-->
<!--                        align="center"-->
<!--                >-->
<!--                </el-table-column>-->
                <el-table-column
                        fixed="right"
                        label="操作"
                        align="center"
                >
                    <template slot-scope="d">
                        <!--如果是三个标签，后两个标签padding-left: 10px;-->
                        <i @click="xiugai(d.row)" style="font-size:18px;color: #409EFF" class="el-icon-edit"></i>
                        <i @click="luojisc(d.row)" style="font-size:18px;padding-left: 20px;color: #409EFF" class="el-icon-delete"></i>
                    </template>
                </el-table-column>
            </el-table>
        </div>


        <!--分页框-->
        <div style="margin-top: 15px;border: 1px solid #BFBFBF;padding: 10px;background-color: white">
            <div style="text-align: center">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page.sync="currentPage"
                        :page-sizes="sizes"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="totalSize"
                >
                </el-pagination>
            </div>
        </div>

        <!--统计图-->
        <div style="margin-top: 15px;border: 1px solid #BFBFBF;padding: 10px;background-color: white">
            <div style="text-align: center">
                <el-row :gutter="20">
                    <el-col :span="8">
                        <span style="font-weight: 600; margin-left: 20px">分布</span>
                        <div id="echartsDemo" style="width: 350px;height: 330px;margin-top: 10px">
                        </div>
                        <el-select v-model="fengbu"  @change="ryfbcx" placeholder="全部数据" style="width: 250px;height: 45px;margin-left: -46px;margin-top: -90px">
                            <el-option
                                    v-for="item in fengbus"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="8">
                        <span style="font-weight: 600; margin-left: 20px">Top</span>
                        <div id="echartsBarDemo" style="width: 350px;height: 330px;margin-top: 10px;margin-left: -10px"></div>
                        <el-select v-model="top" @change="zhuxing" placeholder="全部数据" style="width: 250px;height: 45px;margin-left: -60px;margin-top: -90px">
                            <el-option
                                    v-for="item in tops"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="8">
                        <span style="font-weight: 600; margin-left: 20px">工具</span>
                        <div id="echartsBarDemo1" style="width: 350px;height: 330px;margin-top: 10px;margin-left: -10px"></div>
                        <el-select v-model="gongju" @change="zhexian" placeholder="全部数据" style="width: 250px;height: 45px;margin-left: -46px;margin-top: -90px">
                            <el-option
                                    v-for="item in gongjus"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </el-col>
                </el-row>
            </div>
        </div>

    </div>
</template>

<script>
    import {formatTimeToStr} from '../router//format.js'
    export default {
        name: "Lxsfy",
        data() {
            return {
                multipleTable: [],//存放选中值的数组
                isOne:true,//选中项为1就出现添加跟进记录和修改
                //解除搜索是否显示
                seek:false,
                //下拉选择框
                options3: [{
                    label: '费用类别',
                    options: [{
                        value: '交通',
                        label: '交通'
                    }, {
                        value: '礼品',
                        label: '礼品'
                    }]
                },{
                    label: '审批类型',
                    options: [{
                        value: '未审核',
                        label: '未审核'
                    },]
                }],
                fenlei: '',
                //场景一
                cjy:true,
                //场景二
                cje:false,
                //搜索框
                search: '',
                //表格
                xsfylist: [],
                //分页
                totalSize:10,
                pageSize:5,
                currentPage:1,
                sizes:[5, 10, 15, 20],
                fengbu:'全员费用/人员分布（已审核）',
                fengbus:[{
                    value: '全员费用/人员分布（已审核）',
                    label: '全员费用/人员分布（已审核）'
                }, {
                    value: '费用类别分布',
                    label: '费用类别分布'
                }],
                top:'全员费用/人员分布（已审核）',
                tops:[{
                    value: '全员费用/人员分布（已审核）',
                    label: '全员费用/人员分布（已审核）'
                },{
                    value: '客户费用（已审核）top20',
                    label: '客户费用（已审核）top20'
                }],
                gongju:'全员费用/人员分布（已审核）',
                gongjus:[{
                    value: '全员费用/人员分布（已审核）',
                    label: '全员费用/人员分布（已审核）'
                }, {
                    value: '费用类别统计',
                    label: '费用类别统计'
                }]
            }
        },
        mounted () {

        },
        methods: {
            //圆形查询方法
            yx(){
                this.$axios.get("http://localhost:8088/vue/xsfyfb",{params:{vv:this.fengbu}})
                    .then(v=>{
                        this.drawLine(v.data)//圆形统计图方法
                    }).catch();
            },
            yxx(){
                this.$axios.get("http://localhost:8088/vue/zhuxing",{params:{vv:this.top}})
                    .then(v=>{
                        this.drawBar(v.data)//圆形统计图方法
                    }).catch();
            },
            yxxx(){
                this.$axios.get("http://localhost:8088/vue/zhexian",{params:{vv:this.gongju}})
                    .then(v=>{
                        this. dddf(v.data)//圆形统计图方法
                    }).catch();
            },
            ryfbcx(v){
                this.yx(v);
            },
            zhuxing(v){
                this.yxx(v);
            },
            zhexian(v){
                this.yxxx(v);
            },
            /*销售费用分页查询*/
            initData(currentPage,pageSize,search,fenlei){
                this.$axios.get("http://localhost:8088/vue/cxxsfy",{params:{currentPage:currentPage,pageSize:pageSize,search:search,fenlei:fenlei}}).then(v=>{

                    this.xsfylist=v.data.row;
                    this.totalSize=v.data.total;

                }).catch();
            },

            /*表格删除方法*/
            deleteRow(index, rows) {
                rows.splice(index, 1);
            },
            /*分页数方法*/
            handleSizeChange(val) {
                this.initData(1,this.pageSize =val);
            },
            /*当前页方法*/
            handleCurrentChange(page) {
                this.initData(page,this.pageSize);
            },
            //复选框选中的
            handleSelectionChange(val) {
                this.multipleTable = val;//  this.multipleTable 选中的值
                if(this.multipleTable.length>0){
                    this.cjy=false;//第一行隐藏
                    this.cje=true;//批量操作栏出现
                }
                //选中项大于1不能执行添加跟进记录和修改按钮
                if(this.multipleTable.length>1){
                    this.isOne=false;
                }else if(this.multipleTable.length==0){//选中项为0时
                    this.cjy=true;//第一行出现
                    this.cje=false;//批量操作栏隐藏
                }else{
                    this.isOne=true;//添加跟进记录和修改出现
                }

            },
            /*选择类型商机方法*/
            changebusni(){
                if(this.fenlei!=''){
                    this.seek=true;
                    this.initData(this.currentPage,this.pageSize,this.search,this.fenlei);
                }
            },
            /*解除选择类型商机方法*/
            cancelseek(){
                this.fenlei='';
                this.seek=false;
                this.initData(this.currentPage,this.pageSize,this.search,this.fenlei);
            },

            //回车查询
            ajaxLoginApi(){
                this.initData(this.currentPage,this.pageSize,this.search,this.fenlei);
            },
            //修改方法
            xiugai(cp){

                this.$router.push({
                    path:'/xsfytk',
                    query: {key:cp}
                });
            },

            /*表格逻辑删除方法*/
            luojisc(d){
                this.$confirm('是否确定删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    d.xsfyZhuangtai=0
                    this.$axios.post("http://localhost:8088/vue/addlxsfy",d)
                        .then(()=>{
                            this.$message({
                                showClose: true,
                                type: 'success',
                                message: '删除成功!',
                            });
                            this.initData(this.currentPage,this.pageSize);
                        }).catch(()=>{
                            this.$message({
                                showClose: true,
                                message: '删除失败',
                                type: 'error'
                            });
                        }
                    )
                }).catch(() => {
                    this.$message({
                        showClose: true,
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },

            // 统计图
            drawLine (aa) {
                this.data1 = [];
                for (let a = 0; a < aa.shul1.length; a++) {
                    this.data1.splice(a,0,{
                        name: aa.shul1[a],
                        value: aa.shul[a]
                    });
                }
                let elementById = document.getElementById('echartsDemo')
                let echartsDemo = this.$echarts.init(elementById)

                let option = {
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b}: {c} ({d}%)'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 10,
                        data: []
                    },
                    series: [
                        {
                            name: '访问来源',
                            type: 'pie',
                            radius: ['0%', '75%'],
                            avoidLabelOverlap: false,
                            label: {
                                normal: {
                                    show: false,
                                    position: 'center'
                                },
                                emphasis: {
                                    show: true,
                                    textStyle: {
                                        fontSize: '30',
                                        fontWeight: 'bold'
                                    }
                                }
                            },
                            labelLine: {
                                normal: {
                                    show: false
                                }
                            },
                            data: this.data1
                        }
                    ]
                }
                echartsDemo.setOption(option)

            },
            //柱形统计图
            drawBar (aa) {
                let echartsBarDemo = this.$echarts.init(document.getElementById('echartsBarDemo'))

                echartsBarDemo.setOption({
                    color: ['#3398DB'],
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    grid: {
                        left: '6%',
                        right: '3%',
                        bottom: '10%',
                        containLabel: true
                    },
                    xAxis: [
                        {
                            type: 'category',
                            data: aa.shul1,
                            axisTick: {
                                alignWithLabel: true
                            }
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value'
                        }
                    ],
                    series: [
                        {
                            name: '直接访问',
                            type: 'bar',
                            barWidth: '60%',
                            data: aa.shull
                        }
                    ]
                })
            },
            dddf(aa){
                let echartsBarDemo1 = this.$echarts.init(document.getElementById('echartsBarDemo1'))
                echartsBarDemo1.setOption({
                    tooltip: {
                        trigger: 'item',
                        formatter: '{b}: {c}'
                    },
                    grid: {
                        left: '6%',
                        right: '3%',
                        bottom: '10%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: aa.shul1
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        data:aa.shull,
                        type: 'line',
                        areaStyle: {}
                    }]
                })

            }

        },
        computed:{

            count(){
                return this.multipleTable.length
            }
        } ,
        created:function(){
            //调用分页
            this.initData(this.currentPage,this.pageSize);
            //下拉列查询
            this.changebusni();
            //调用回车方法
            this.ajaxLoginApi();
            //调用圆形统计图
            this.yx();
            //调用柱形统计图
            this.yxx();
            //调用折线统计图
            this.yxxx();
         },
        filters: {
            formatDate: function (time) {
                if (time != null && time != "") {
                    var date = new Date(time);
                    return formatTimeToStr(date, "yyyy-MM-dd");
                } else {
                    return "";
                }
            }
        }

    }
</script>

<style scoped>

    .addview:hover{
        color: white;
    }
    a{
        text-decoration: none;
        color: #409EFF;
    }
    a:hover{
        color: white;
    }
    .busin:hover{
        color: #3E84E9;
        cursor:pointer;
    }
    .businame{
        color: #606266;
    }
    .businame:hover{
        color: #409EFF;
        cursor:pointer;
    }
    .operate{
        font-size: 12px;
        height: 40px;
        padding: 0 20px;
        color: #777;
        background: white;
    }
    .selected—title{
        margin-top: 15px;
        margin-left: -6px;
        border-right: 1px solid #e6e6e6;
        width: 86px;
        height:20px;
        float: left;
    }
    .selected—title1{
        margin-top: 15px;
        border-right: 1px solid #e6e6e6;
        width: 86px;
        height:20px;
        float: left;
        cursor: pointer;
    }

    .selected—title1 span{
        margin-left: 24px;
    }
    .selected—title1 span:hover{
        color:#409eff;
    }
    .selected—title2{
        margin-top: 15px;
        border-right: 1px solid #e6e6e6;
        width: 129px;
        height:20px;
        float: left;
        cursor: pointer;
    }

    .selected—title2 span{
        margin-left: 24px;
    }
    .selected—title2 span:hover{
        color:#409eff;
    }
</style>